package castle.defense.project;

import java.util.ArrayList;

import android.graphics.Canvas;

public class ImmobileWeaponSet {
	
	public static ImmobileWeaponSet createBasicSet() {
		ImmobileWeaponSet ret = new ImmobileWeaponSet();
		ret.addWeapon(Weapon.createGun());
		ret.addWeapon(Weapon.createGun());
		if(Options.getDifficulty() == Options.easy)
			ret.addWeapon(Weapon.createGun());
		return ret;
	}
	ArrayList<ImmobileWeapon> set;
	public ImmobileWeaponSet() {
		set = new ArrayList<ImmobileWeapon>();
	}
	
	public Projectile attack(double x, double y) {
		PhysicsPoint target = new PhysicsPoint(x,y);
		double bestDist = 1e9;
		ImmobileWeapon best = null;
		for(ImmobileWeapon iw : set) {
			double dist = iw.point.getDistance(target);
			if(iw.canAttack() && dist < bestDist) {
				best = iw;
				bestDist = dist;
			}
		}
		if(best==null)
			return null;
		return best.attack(x, y);
	}
	
	public void update(long milli) {
		for(ImmobileWeapon iw : set) {
			iw.update(milli);
		}
	}
	
	public void addWeapon(ImmobileWeapon w) {
		set.add(w);
		double spread = PE.screenPercentX(100)/(set.size()+1);
		int i = 1;
		for(ImmobileWeapon iw : set) {
			iw.point.x = spread * (i++);
		}
	}
	
	public void draw(Canvas c) {
		for(ImmobileWeapon iw : set) {
			iw.draw(c);
		}
	}
}
